def alfavit(word):
    words={
        "zero":"0",
        "one":"1",
        "two":"2",
        "three":"3",
        "four":"4",
        "five":"5",
        "six":"6",
        "seven":"7",
        "eight":"8",
        "nine":"9",
    }
    return words.get(word)
def pr(n):
    if n<=1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True
input_words=input().split()
if len(input_words)!=3:
    print('Wrong input')
else:
    number_str = "".join([alfavit(word) for word in input_words])
    if not number_str.isdigit() or len(number_str)!=3:
        print('Wrong input')
    else:
        number = int(number_str)
        l = None
        u= None
        i = 1
        while True:
            if number - i >= 0 and pr(number-i):
                l=number-i
                break
            if pr(number+i):
                u=number+i
                break
            i+=1
        if l is not None:
            print(l)
        elif u is not None:
            print(u)
